package com.cat.enumerate;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/check-if-move-is-legal/description/?envType=problem-list-v2&envId=enumeration
 * @create 2025/9/20 20:58
 * @since JDK17
 */

public class Solution07 {
    static int[][]d = new int[][]{{-1, 0}, {1, 0}, {0, -1}, {0, 1}, {-1, -1}, {-1, 1}, {1, -1}, {1, 1}};

    public boolean checkMove(char[][] board, int rMove, int cMove, char color) {
        char want = color == 'b' ? 'w' : 'b';
        for (int i = 0; i < 8; i++) {   // 八个方向
            int r = rMove, c = cMove, cnt = 0;
            while (true) {
                int nx = r + d[i][0], ny = c + d[i][1];
                if (nx < 0 || nx > 7 || ny < 0 || ny > 7) { // 越界
                    continue;
                }
                if (board[nx][ny] == '.') {
                    break;
                }
                if (board[nx][ny] == color && cnt > 0) {    // 满足条件
                    return true;
                }
                cnt++;
            }
        }

        return false;
    }
}
